﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.XPath;

namespace WinSCP.API
{
    public class FileSystemObject
    {
        public FileSystemObject(XPathNavigator node, XmlNamespaceManager ns)
        {
            this._filename = node.SelectSingleNode("w:filename/@value", ns).Value;
            this._objType = node.SelectSingleNode("w:type/@value", ns).Value == "-" ?
                ObjectType.File : ObjectType.Directory;
            this._modifyStamp = DateTime.Parse(node.SelectSingleNode("w:modification/@value", ns).Value);
            this._permissions = node.SelectSingleNode("w:permissions/@value", ns).Value;
            if (this._objType == ObjectType.File)
                this._bytes = long.Parse(node.SelectSingleNode("w:size/@value", ns).Value);
        }

        private string _filename;

        public string Filename
        {
            get { return _filename; }
            set { _filename = value; }
        }
        private ObjectType _objType;

        public ObjectType ObjType
        {
            get { return _objType; }
            set { _objType = value; }
        }
        private long _bytes;

        public long Bytes
        {
            get { return _bytes; }
            set { _bytes = value; }
        }
        private DateTime _modifyStamp;

        public DateTime ModifyStamp
        {
            get { return _modifyStamp; }
            set { _modifyStamp = value; }
        }
        private string _permissions;

        public string Permissions
        {
            get { return _permissions; }
            set { _permissions = value; }
        }

        public enum ObjectType : byte
        {
            File = 0,
            Directory = 1
        }
    }
}
